package com.eco.fanliapp.controller.app;


import com.eco.fanliapp.common.base.BaseController;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.entity.AppUser;
import com.eco.fanliapp.service.ISyModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 模块表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-09-09
 */
@RestController
@RequestMapping("/mobile/home")
public class SyModuleAppController extends BaseController {


    @Autowired
    private ISyModuleService iSyModuleService;


    @GetMapping(value = "/banner/list")
    public ServerResponse list(){
        AppUser appUser = getAppUser();
        if(appUser != null && appUser.getCompanyId() !=  null){
            return iSyModuleService.moduleListCompany(appUser.getCompanyId());
        }
        return iSyModuleService.moduleListCompany(null);
    }

    /**
     * banner免单
     * @return
     */
    @GetMapping(value = "/banner/freeList")
    public ServerResponse bannerFreeList(HttpServletRequest request){
        String version = request.getHeader("version");
        AppUser user = getAppUser();
        if(version != null && version.compareTo("2.4.7") >= 0){
            return iSyModuleService.bannerFreeList(null,user);
        }
        return ServerResponse.createBySuccessCodeMessage(201,"版本低于2.4.7");
    }

    /**
     * banner广告位
     * @return
     */
    @GetMapping(value = "/banner/advertisingList")
    public ServerResponse bannerAdvertisingList(){
        AppUser appUser = getAppUser();
        if(appUser != null && appUser.getCompanyId() !=  null){
            return iSyModuleService.bannerAdvertisingList(appUser.getCompanyId());
        }
        return iSyModuleService.bannerAdvertisingList(null);
    }

    /**
     * banner淘宝活动（未使用）
     * @return
     */
    @GetMapping(value = "/banner/taoBaoActivityList")
    public ServerResponse bannerTaoBaoActivityList(){
        return iSyModuleService.bannerTaoBaoActivityList(null);
    }

    /**
     * 模块总开关
     * @return
     */
    @GetMapping(value = "/module/onOffList")
    public ServerResponse moduleOnOffList(){
        return  iSyModuleService.moduleOnOffList();
    }

    /**
     * 三步省钱
     * @return
     */
    @GetMapping(value = "/money/tutorial")
    public ServerResponse moneyTutorial(){
        return  iSyModuleService.moneyTutorial();
    }

    /**
     * 今日爆款/白菜专区**聚划算，淘抢购
     * @return
     */
    @GetMapping(value = "/kingKongSon/list")
    public ServerResponse todayHotList(@RequestParam(defaultValue = "1")Integer currentPage,@RequestParam(defaultValue = "20")Integer pageSize,@RequestParam(defaultValue = "0")Integer cid,Integer type){
        int star = (currentPage - 1)*pageSize;
        int end = currentPage*pageSize;
        return  iSyModuleService.kingKongSonList(star,end,cid,type);
    }

    /**
     * 首页海报(是否显示)
     * @return
     */
    @GetMapping(value = "/poster/onOff")
    public ServerResponse homePoster(){
        return  iSyModuleService.homePosterModule();
    }


    /**
     * 金刚眼/红包列表
     * @return
     */
    @GetMapping(value = "/module/reveal")
    public ServerResponse moduleReveal(){
        AppUser u = getAppUser();
        if(u == null ){
            return  iSyModuleService.moduleReveal(null);
        }else {
            return  iSyModuleService.moduleReveal(u.getUserId());
        }

    }

    /**
     * 浮窗
     * @return
     */
    @GetMapping(value = "/module/floating")
    public ServerResponse moduleFloating(){
        AppUser u = getAppUser();
        if(u == null ){
            return  iSyModuleService.moduleFloating(null);
        }else {
            return  iSyModuleService.moduleFloating(u.getUserId());
        }

    }

    /**
     * 秒杀小喇叭
     * @return
     */
    @GetMapping(value = "/seckill/trumpet")
    public ServerResponse moduleTrumpet(){
        return iSyModuleService.moduleTrumpet();
    }

    /**
     * 金刚区背景图
     * @return
     */
    @GetMapping(value = "/module/KingBkImage")
    public ServerResponse KingBgImage(){
        return iSyModuleService.KingBgImage();
    }
}
